//
//  Constant.swift
//  EY.Mtel_ProjectTemplate_Swift
//
//  Created by zxj on 2020/7/26.
//  Copyright © 2020 EY.Mtel. All rights reserved.
//

import UIKit

class Constant: NSObject {
    //MARK: -------------------------- 值类型常量
    public static let SCREEN_WIDTH = UIScreen.main.bounds.width
    public static let SCREEN_HEIGHT = UIScreen.main.bounds.height
    
    ///状态栏高度
    public static let STATUS_BAR_HEIGHT = UIApplication.shared.statusBarFrame.height
    
    ///导航栏高度(不包括状态栏)
    public static let NAVI_HEIGHT: CGFloat = 44.0
    
    ///tabBar高度
    public static let TAB_BAR_HEIGHT: CGFloat = 49.0
    
    ///iPhone X 底部操作条预留高度
    public static let IPX_BOTTOM_BAR_HEIGHT: CGFloat = 34.0
    
    //MARK: -------------------------- 值类型计算属性
    ///是否是 iPhone X
    public static var isIPX: Bool {
        return Constant.keyWindow.frame.height == 812.0
    }
    
    ///导航栏安全高度
    public static var safeNaviHeight: CGFloat {
        return Constant.STATUS_BAR_HEIGHT + Constant.NAVI_HEIGHT
    }
    
    ///tabBar安全高度
    public static var safeTabBarHeight: CGFloat {
        return Constant.TAB_BAR_HEIGHT + (Constant.isIPX ? Constant.IPX_BOTTOM_BAR_HEIGHT : 0)
    }
    
    ///带有不透明导航栏和不透明tabBar的页面的安全高度
    public static var safeHeightWithNaviAndTab: CGFloat {
        return Constant.SCREEN_HEIGHT - Constant.safeNaviHeight - Constant.safeTabBarHeight
    }
    
    ///带有不透明导航栏的页面的安全高度
    public static var safeHeightWithNavi: CGFloat {
        return Constant.SCREEN_HEIGHT - Constant.safeNaviHeight - (Constant.isIPX ? Constant.IPX_BOTTOM_BAR_HEIGHT : 0)
    }
    
    //MARK: -------------------------- 值类型计算属性 - 沙盒路径
    public static var SANDBOX_HOME_PATH: String {
        return NSHomeDirectory()
    }
    public static var SANDBOX_DOC_PATH: String {
        if let path = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first {
            return path
        }
        return Constant.SANDBOX_TMP_PATH
    }
    public static var SANDBOX_LIB_PATH: String {
        if let path = NSSearchPathForDirectoriesInDomains(.libraryDirectory, .userDomainMask, true).first {
            return path
        }
        return Constant.SANDBOX_TMP_PATH
    }
    public static var SANDBOX_CACHES_PATH: String {
        if let path = NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true).first {
            return path
        }
        return Constant.SANDBOX_TMP_PATH
    }
    public static var SANDBOX_TMP_PATH: String {
        return NSTemporaryDirectory()
    }
    
    //MARK: -------------------------- 引用类型常量
    public static let appDelegate: AppDelegate = UIApplication.shared.delegate as! AppDelegate
    public static let keyWindow = Constant.appDelegate.window!
    

}
